// src/pages/home/index.js
import {homeMenu} from "../../actions/homeMenu";
import {Storage} from "../../utils/storage";
const Core = require('../../../node_modules/zk-mini-core/miniprogram_dist/index');
const App = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    title:'工作台',
    menuMap: Storage.get('menuMap'),
    items: [],
    footHeight: 0,
    PageCur: "root",

  },

  /**
   * 组件的方法列表
   */
  methods: {
    onLoad: function (options) {

    this.loadShowTabbarMenu();
     // 获取底部tab高度
     let query = wx.createSelectorQuery()
     query.select('#foot').boundingClientRect(res => {      
       console.log("高度：" + res.height);
       this.setData({
         footHeight: res.height
       })        
     }).exec()

      //重新渲染菜单权限
    let menuList = homeMenu.loadShowRootMenuMap(JSON.parse(options.menuArr));
    this.setData({
      items:menuList
    })
    },
    clickAction(e) {
      let itemkey = e.currentTarget.dataset.key;
      console.log('key',itemkey)
      Core.navigateTo(itemkey);
    },
    loadShowTabbarMenu: function(){
      let menuMap = Storage.get('menuMap')
      this.setData({
        menuMap: menuMap
      })
      //重新渲染小程序权限
      if(menuMap == undefined){
        return
      }
      if(menuMap.appmainBoard == 'true'){
        this.setData({
          PageCur: 'root'
        })
        return
      }
      if(menuMap.appmessagemanager == 'true'){
        this.setData({
          PageCur: 'message'
        })
        return
      }
      if(menuMap.appmyuserInfo == 'true'){
        this.setData({
          PageCur: 'mine'
        })
        return
      }
    },
    NavChange: function (event) {
      this.setData({
        PageCur: event.currentTarget.dataset.cur
      })
      switch (this.data.PageCur){
        case 'root':
          this.setData({
            title:'工作台'
          })
        break;
        case 'message':
          this.setData({
            title:'消息'
          })
        break;
        case 'mine':
          this.setData({
            title:'我的'
          })
        break;
      }
    },
  },
  ready() {

    

  }
})